package ph.gov.marikina.mcsmtms.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import ph.gov.marikina.mcsmtms.dao.LookupDAO;
import ph.gov.marikina.mcsmtms.dao.utils.LookupRowMapper;
import ph.gov.marikina.mcsmtms.domain.Lookup;

// TODO: Auto-generated Javadoc
/**
 * The Class LookupDAOImpl.
 */
public class LookupDAOImpl extends JdbcDaoSupport implements LookupDAO {
	
	/** The select all situation types sql. */
	final String SELECT_ALL_SITUATION_TYPES_SQL = "select * from l_situation_type";
	
	/** The select all roads sql. */
	final String SELECT_ALL_ROADS_SQL = "select * from l_road";
	
	/** The select all traffic condition types sql. */
	final String SELECT_ALL_TRAFFIC_CONDITION_TYPES_SQL = "select * from l_traffic_condition_type order by sort_order";
	
	/** The select all user types sql. */
	final String SELECT_ALL_USER_TYPES_SQL = "select * from l_user_type";
	
	/** The select all types of report source. */
	final String SELECT_ALL_REPORT_SOURCE_SQL = "select * from l_report_source";
	
	/** The select all types of direction. */
	final String SELECT_ALL_DIRECTION_SQL = "select * from l_direction";
	
	/** The log. */
	Logger log = Logger.getLogger(LookupDAOImpl.class);

//	private SessionFactory sessionFactory;
//	
//	@Autowired
//	public void setSessionFactory(SessionFactory sessionFactory) {
//		this.sessionFactory = sessionFactory;
//	}
	
	/* (non-Javadoc)
	 * @see ph.gov.marikina.mcdrrmo.dao.LookupDAO#selectAllSituationTypes()
	 */
	@Override
	public List<Lookup> selectAllSituationTypes() {
		JdbcTemplate select = new JdbcTemplate(getDataSource());
		return select.query(SELECT_ALL_SITUATION_TYPES_SQL, new LookupRowMapper());
	}

	/* (non-Javadoc)
	 * @see ph.gov.marikina.mcdrrmo.dao.LookupDAO#selectAllRoads()
	 */
	@Override
	public List<Lookup> selectAllRoads() {
		JdbcTemplate select = new JdbcTemplate(getDataSource());
		return select.query(SELECT_ALL_ROADS_SQL, new LookupRowMapper());
	}

	/* (non-Javadoc)
	 * @see ph.gov.marikina.mcdrrmo.dao.LookupDAO#selectAllTrafficConditionTypes()
	 */
	@Override
	public List<Lookup> selectAllTrafficConditionTypes() {
		JdbcTemplate select = new JdbcTemplate(getDataSource());
		return select.query(SELECT_ALL_TRAFFIC_CONDITION_TYPES_SQL, new LookupRowMapper()); 
	}

	/* (non-Javadoc)
	 * @see ph.gov.marikina.mcdrrmo.dao.LookupDAO#selectAllUserTypes()
	 */
	@Override
	public List<Lookup> selectAllUserTypes() {
		JdbcTemplate select = new JdbcTemplate(getDataSource());
		return select.query(SELECT_ALL_USER_TYPES_SQL, new LookupRowMapper());
	}
	
	public List<Lookup> selectAllDirections() {
		JdbcTemplate select = new JdbcTemplate(getDataSource());
		return select.query(SELECT_ALL_DIRECTION_SQL, new LookupRowMapper());
	}
	
	public List<Lookup> selectAllReportSources() {
		JdbcTemplate select = new JdbcTemplate(getDataSource());
		return select.query(SELECT_ALL_REPORT_SOURCE_SQL, new LookupRowMapper());
	}

}
